package com.ruoyi.common.utils.http;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.exception.ServiceException;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.List;

public class SendHttpPost {



    private static String appId="123123";
    private static String appSecret="baofu888";


    private static  String url="http://hxss.zushijie360.com/submitUsers";

    public static String sendHttpPost(HttpDomain domain) {
        domain.setAppId(appId);
        domain.setSign(appSecret);
        //校验签名
        String signStr = appId +appSecret + JSON.toJSONString(domain.getHmdList());
        System.out.println(signStr);
        String sign = DigestUtils.md5DigestAsHex(signStr.getBytes(StandardCharsets.UTF_8));
        System.err.println(sign);
        domain.setSign(sign);

        String result = null;
        result= HttpUtil.post(url, JSON.toJSONString(domain));

        return result;
    }


    public static void main(String[] args) {
        HttpDomain domain = new HttpDomain();
        String s="[\n" +
                "        {\n" +
                "           \"realName\": \"用志明\",\n" +
                "            \"idCard\": \"370100197207121485\",\n" +
                "            \"mobile\": \"16407958632\",\n" +
                "            \"type\": \"1\",\n" +
                "            \"remark\": \"撸子\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"realName\": \"牵梓玥\",\n" +
                "            \"idCard\": \"210100194708208708\",\n" +
                "            \"mobile\": \"15977601386\",\n" +
                "            \"type\": \"4\",\n" +
                "            \"remark\": \"骗子\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"realName\": \"学雨桐\",\n" +
                "            \"idCard\": \"510104197607249519\",\n" +
                "            \"mobile\": \"17439784752\",\n" +
                "            \"type\": \"2\",\n" +
                "            \"remark\": \"老赖\"\n" +
                "        }\n" +
                "    ]";
        List<HmdBo> hmdList = JSON.parseArray(s, HmdBo.class);




        domain.setHmdList(hmdList);
        String result = sendHttpPost(domain);
        System.err.println(result);

//        String sign = DigestUtils.md5DigestAsHex("123123baofu888[HmdBo(realName=用志明, idCard=370100197207121485, mobile=16407958632, type=1, remark=撸子), HmdBo(realName=牵梓玥, idCard=210100194708208708, mobile=15977601386, type=4, remark=骗子), HmdBo(realName=学雨桐, idCard=510104197607249519, mobile=17439784752, type=2, remark=老赖)]".getBytes(StandardCharsets.UTF_8));
//        System.err.println(sign);

//        System.err.println("4c9b44cfe834b8082c9d1cc6ec55387c".equals("4c9b44cfe834b8082c9d1cc6ec55387c"));
    }
}
